/*
 * adc-ss805x.h
 *
 * adc driver.
 *
 * Copyright (C) 2024 Sinh Micro, Inc.
 * Subject to the GNU Public License, version 2.
 *
 * Author: lixiang<lixiang@sinhmicro.com>
 * 
 * Encoding format: GB2312
 * Version: v1.2.2
 * Date: 2024-11-05
 */

#ifndef _ADC_SS805X_H
#define _ADC_SS805X_H

    #define ADC_SET_START()                 (ADCCON0 |= (1 << 6))    
    #define ADC_CLR_START()                 (ADCCON0 &= ~(1 << 6))

    #define ADC_CONTINUE_MODE()             (ADCCON0 |= (1 << 3))    
    #define ADC_SIGLE_MODE()                (ADCCON0 &= ~(1 << 3))

    #define AN0_AMP8_EN()                   (ADCAMP = (ADCAMP & 0xFC) | 0x02)
    #define AN0_AMP8_DIS()                  (ADCAMP &= 0xFC)

    #define AN1_AMP8_EN()                   (ADCAMP = (ADCAMP & 0xF3) | 0x08)
    #define AN1_AMP8_DIS()                  (ADCAMP &= 0xF3)

    #define AN2_AMP8_EN()                   (ADCAMP = (ADCAMP & 0xCF) | 0x20)
    #define AN2_AMP8_DIS()                  (ADCAMP &= 0xCF)

    #define ADC_AN0DIV_EN()                 (ADCCON1 |= 0x04)
    #define ADC_AN0DIV_DIS()                (ADCCON1 &= ~0x04)

    #define ADC_AN1DIV_EN()                 (ADCCON1 |= 0x08)
    #define ADC_AN1DIV_DIS()                (ADCCON1 &= ~0x08)

    #define ADC_2500_VREF()                 (ADCCON1 |= 0x10)
    #define ADC_2000_VREF()                 (ADCCON1 &= ~0x10)

    #define ADC_IS_EOSIF()                  ((ADCCHSEL & (1 << 7)) != 0)
    #define ADC_CLR_EOSIF()                 (ADCCHSEL &= 0xBF)

    #define ADCBGRTRIM                      (*(volatile unsigned char xdata*)(0xFE48))

#endif
